from process import db_connect
from process import baseFunction as bf
from process.Line_data import FLOATMV
import json
from typing import Dict, List, Optional

def Line_daily_floatMv_amount(tsCode: str, period: str, table_name:str, columns: List[str]) -> str:
    # 构造返回结果
    result_data = FLOATMV.getLine_daily_floatMv_amount(tsCode, period, table_name, columns)    
    result = db_connect.R(code=200, success=True,
                          msg="Data fetched successfully", data=result_data)

    json_result = json.dumps(result, cls=bf.CustomEncoder)
    return json_result

def Line_daily_data(period: str, tableName:str, columns: str, conditions: Optional[str] = None  ) -> str:
    # 构造返回结果
    # 将 columns 字符串转换为列表
    columns_list = columns.split(',') if isinstance(columns, str) else columns
    
    result_data = bf.getLine_daily_data(period, tableName, columns_list, conditions)    
    result = db_connect.R(code=200, success=True,
                          msg="Data fetched successfully", data=result_data)

    json_result = json.dumps(result, cls=bf.CustomEncoder)
    return json_result